package com.u2ds.console.web.util;

import com.u2ds.core.util.DateUtil;
import org.springframework.util.StringUtils;

import java.io.Serializable;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

public class SmsUtil implements Serializable {
	
	private static int  SMS_OPEN = 1;
	
	public final static int SMS_COUNT = 5;
	
	public final static int SMS_INTERVAL_TIME= 60;
	
	public final static int SMS_VALIDITY_TIME = 180;

	public final static String ID = "1064";

	public final static String ACCOUNT = "lbh";

	public final static String PASSWORD = "123456";

	/**
	 * 
	 */
	private static final long serialVersionUID = 1567221L;

	/**
	 * 成功返回 1  失败返回小于或等于0
	 * @param mobile
	 * @param content
	 * @return
	 * @throws Exception
	 */
	public static int sendSms(String mobile, String content) {
		if(SMS_OPEN == 1){
			Map<String,String> params = new HashMap<String,String>();
			params.put("userid", ID);
			params.put("account", ACCOUNT);
			params.put("password", PASSWORD);
			params.put("mobile", mobile);
			content = "尊敬的用户,您的验证码为"+content+",请勿泄露【乐搏汇运动生活馆】";
			params.put("content", content);
			params.put("sendTime", DateUtil.formatDate(new Date()));
			params.put("action", "send");
			params.put("extno", "");
			String result = HttpUtil.post("http://106.3.37.99:7799/sms.aspx", params);
			if(StringUtils.isEmpty(result)){
				return -2;
			}
			System.out.println("短信正式上线");
			if(result.indexOf("<returnstatus>Success</returnstatus>")!=-1&&result.indexOf("<message>ok</message>")!=-1){
				return 1;
			}
			System.out.println(result);
			return -1;
		}
		System.out.println("模拟发送短信");
		return 1;
	}
	
	public static void main(String[] args) {
//		try {
//			System.out.println(SmsUtil.sendSmsVerify("18225337253", "5461"));
//		} catch (Exception e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
	}
}
